<?php

/**
 * This is the model class for table "volunteer".
 *
 * The followings are the available columns in table 'volunteer':
 * @property integer $id
 * @property string $volunteer_Fname
 * @property string $volunteer_Lname
 * @property integer $volunteer_Age
 * @property string $volunteer_Address
 * @property string $volunteer_Birthdate
 * @property string $volunteer_Picture
 * @property string $volunteer_Status
 * @property string $volunteer_ContactNumber
 * @property integer $Organization_id
 *
 * The followings are the available model relations:
 * @property Donation[] $donations
 * @property Organization $organization
 */
class Volunteer extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Volunteer the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'volunteer';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id, Organization_id', 'required'),
			array('id, volunteer_Age, Organization_id', 'numerical', 'integerOnly'=>true),
			array('volunteer_Fname, volunteer_Lname, volunteer_Address, volunteer_Picture, volunteer_Status, volunteer_ContactNumber', 'length', 'max'=>45),
			array('volunteer_Birthdate', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, volunteer_Fname, volunteer_Lname, volunteer_Age, volunteer_Address, volunteer_Birthdate, volunteer_Picture, volunteer_Status, volunteer_ContactNumber, Organization_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'donations' => array(self::HAS_MANY, 'Donation', 'Volunteer_id'),
			'organization' => array(self::BELONGS_TO, 'Organization', 'Organization_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'volunteer_Fname' => 'Volunteer Fname',
			'volunteer_Lname' => 'Volunteer Lname',
			'volunteer_Age' => 'Volunteer Age',
			'volunteer_Address' => 'Volunteer Address',
			'volunteer_Birthdate' => 'Volunteer Birthdate',
			'volunteer_Picture' => 'Volunteer Picture',
			'volunteer_Status' => 'Volunteer Status',
			'volunteer_ContactNumber' => 'Volunteer Contact Number',
			'Organization_id' => 'Organization',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('volunteer_Fname',$this->volunteer_Fname,true);
		$criteria->compare('volunteer_Lname',$this->volunteer_Lname,true);
		$criteria->compare('volunteer_Age',$this->volunteer_Age);
		$criteria->compare('volunteer_Address',$this->volunteer_Address,true);
		$criteria->compare('volunteer_Birthdate',$this->volunteer_Birthdate,true);
		$criteria->compare('volunteer_Picture',$this->volunteer_Picture,true);
		$criteria->compare('volunteer_Status',$this->volunteer_Status,true);
		$criteria->compare('volunteer_ContactNumber',$this->volunteer_ContactNumber,true);
		$criteria->compare('Organization_id',$this->Organization_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}